﻿using System.Security.Principal;
using System.Web.Mvc;
using ENail.Domain.Core;
using ENail.Portal.Web.Models;

namespace ENail.Portal.Web.Controllers
{
    public class BaseController : Controller
    {
        public BaseController() : base()
        {
        }

        protected void ClearModelError()
        {
            foreach (ModelState modelState in ModelState.Values)
            {
                modelState.Errors.Clear();
            }
        }

        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //We would add authorize user once we implement right/role permission
            //AuthorizedUser();
            base.OnActionExecuted(filterContext);
        }

        private void AuthorizedUser()
        {
            //var currentUser = (User)User;

            //IPrincipal principal = User;
            //var currentUser = (User) principal;

            //var currentUser = (UserViewModel) User;

            //if (currentUser.IsInRole(this.GetType().Name))
            //    Response.Redirect("NotAuthorized.aspx", true);

            if (User == null)
                Response.Redirect("/Login/LogOn");
        }
    }
}
